﻿using System;

namespace Utilities
{
    public class Validator
    {
        public static bool IsUShort(object value)
        {
            return (Protector.UShort(value, true) != null);
        }

        public static bool IsUInt(object value)
        {
            return (Protector.UInt(value, true) != null);
        }

        public static bool IsULong(object value)
        {
            return (Protector.ULong(value, true) != null);
        }

        public static bool IsByte(object value)
        {
            return (Protector.Byte(value, true) != null);
        }

        public static bool IsShort(object value)
        {
            return (Protector.Short(value, true) != null);
        }

        public static bool IsInt(object value)
        {
            return (Protector.Int(value, true) != null);
        }

        public static bool IsLong(object value)
        {
            return (Protector.Long(value, true) != null);
        }

        public static bool IsDouble(object value)
        {
            return (Protector.Double(value, true) != null);
        }

        public static bool IsDecimal(object value)
        {
            return (Protector.Decimal(value, true) != null);
        }

        public static bool IsBool(object value)
        {
            return (Protector.Bool(value, true, true) != null);
        }

        public static bool IsDateTime(object value)
        {
            return (Protector.DateTime(value, true) != null);
        }

        public static bool IsDateTime(object value, string format)
        {
            return (Protector.DateTime(value, format, true) != null);
        }

        public static bool IsString(object value)
        {
            return (Protector.String(value, true) != null);
        }

        public static bool IsObject(object value, Type type)
        {
            return (Protector.Object(value, type, true) != null);
        }

        public static bool IsType(object value, TypeCode typeCode)
        {
            switch (typeCode)
            {
                case TypeCode.UInt16:
                    return IsShort(value);
                case TypeCode.UInt32:
                    return IsShort(value);
                case TypeCode.UInt64:
                    return IsLong(value);
                case TypeCode.Byte:
                    return IsByte(value);
                case TypeCode.Int16:
                    return IsShort(value);
                case TypeCode.Int32:
                    return IsInt(value);
                case TypeCode.Int64:
                    return IsLong(value);
                case TypeCode.Double:
                    return IsDouble(value);
                case TypeCode.Decimal:
                    return IsDecimal(value);
                case TypeCode.Boolean:
                    return IsBool(value);
                case TypeCode.DateTime:
                    return IsDateTime(value);
                case TypeCode.String:
                    return IsString(value);
                default:
                    return false;
            }
        }

        public static bool IsEnumByName<T>(object enumItemName)
        {
            if (enumItemName == null)
                return false;

            T defaultValue = default(T);
            return Protector.EnumTryParseByName<T>(enumItemName.ToString(), ref defaultValue);
        }

        public static bool IsEnumByValue<T>(int enumItemValue)
        {
            T defaultValue = default(T);
            return Protector.EnumTryParseByValue<T>(enumItemValue, ref defaultValue);
        }
    }
}
